package com.shishuo.cms.tag;

import static freemarker.template.ObjectWrapper.BEANS_WRAPPER;

import java.io.IOException;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.shishuo.cms.entity.CustomTagHtml;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

@Service
public class CustomTagHtmlTag extends BaseTagPlugin{

	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		String name = params.get("name").toString();
		try {
			CustomTagHtml customTagHtml =customTagHtmlService.getByName(name);
			env.setVariable("tag_html_value", BEANS_WRAPPER.wrap(customTagHtml));
			body.render(env.getOut());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
